﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FortuneHeaven.Admin.Common;
using FortuneHeavenBAL;
using FortuneHeavenCommon.DataMap;

namespace FortuneHeaven.Admin.Pages.GameManager
{
    public partial class RoomTableDetailList : FortuneHeaven.Admin.Common.PageBase
    {
        private string pre;
        public override string PageID
        {
            get { return "F52"; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            lblDeptName.Text = "房间桌子明细统计";
            this.usPager.PagerChanged += new Admin.Controls.Pagination.PagerChangeHandler(usPager_PagerChanged);
            if (!this.IsPostBack)
            {
                this.drpPagerSize.Items.Clear();
                this.drpPagerSize.Items.Add(new ListItem("每页10行", "10"));
                this.drpPagerSize.Items.Add(new ListItem("每页20行", "20"));
                this.drpPagerSize.Items.Add(new ListItem("每页50行", "50"));

                //if (!string.IsNullOrEmpty(Request["orderid"]))
                //{
                //    this.txtOrderID.Text = Request["orderid"];
                //}

                if (!AuthorityCenter.IsAdmin)
                {
                    AdminUserBO userbo = new AdminUserBO();
                    AdminUser user = userbo.GetInfo(AuthorityCenter.CurrentUserID);
                    this.txtOrderID.Text = user.RoomFilter;
                }
                this.txtOrderID.Visible = false;
                this.btnSearch.Visible = false;
                lbGiftOrder.Visible = false;
                if (!string.IsNullOrEmpty(Request["pagesize"]))
                {
                    this.drpPagerSize.SelectedIndex = int.Parse(Request["pagesize"]);
                }
                else
                {
                    this.drpPagerSize.SelectedValue = "10";
                }

                if (!string.IsNullOrEmpty(Request["current"]))
                {
                    ResetList(int.Parse(Request["current"]));
                }
                else
                {
                    ResetList();
                }
                //this.lvNews.ItemCommand += new EventHandler<ListViewCommandEventArgs>(lvNews_ItemCommand);

            }
        }
        private void usPager_PagerChanged(object sender, int currentpage)
        {
            Refresh();
        }

        public void Refresh()
        {
            animalrecordBO giftorder = new animalrecordBO();

            lvNews.DataSource = giftorder.GetList(this.usPager.CurrentPageIndex, int.Parse(this.drpPagerSize.SelectedValue), GetRoomID(), GetTableID());
            lvNews.DataBind();
        }

        protected void drpPagerSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            ResetList();
        }

        public void ResetList()
        {
            ResetList(1);
        }

        public void SearchValue(object sender, EventArgs e)
        {
            ResetList();
        }

        public void ResetList(int current)
        {

            animalrecordBO giftorder = new animalrecordBO();
            this.usPager.RecordCount = giftorder.GetTotalSize(GetRoomID(),GetTableID());
            this.usPager.PageSize = int.Parse(this.drpPagerSize.SelectedValue);
            this.usPager.Initial();
            this.usPager.CurrentPageIndex = 1;
        }

        public string GetRoomID()
        {
            string roomid = Request["RoomID"];
            if (!string.IsNullOrEmpty(this.txtOrderID.Text))
            {
                string[] content = this.txtOrderID.Text.Split(',');
                foreach(string k in content)
                {
                    if (k.Trim() == roomid)
                    {
                        return k.Trim();
                    }
                }
            }
            return roomid;
        }

        public string GetTableID()
        {
            return Request["TableID"];
        }

        public long GetTotal(object left, object cotain)
        {
            int first = 0;
            Int64 second = 0;
            if (left != null && left is int)
            {
                first = (int)left;
            }
            if (cotain != null && cotain is Int64)
            {
                second = (Int64)cotain;
            }
            return (long)first + (long)second;

        }
        public string GetPrizeInfor(object AnimalType, object AnimalColorcode, object AnimalMode, object AnimalFlag, object AnimalInfoEx)
        {
            string animalName1 = GetAnimalNameByID((int)AnimalType);
            string animalColor1 = GetAnimalColorByID((int)AnimalColorcode);
            string animalPrize = GetAnimalPrizeByID((int)AnimalMode);
            string animalPrizeInfo = animalColor1 + animalName1 + "[" + animalPrize + "]" + "[" + AnimalFlag + "]";
            if ((int)AnimalMode == 4)
            {
                animalPrizeInfo = animalPrizeInfo + "[" + AnimalInfoEx + "]";
            }
            return animalPrizeInfo;
        }


        public string GetAnimalNameByID(int ID)
        {
            string AnimalName = "未知动物";
            switch (ID)
            {
                case 0:
                    AnimalName = "狮子";
                    break;
                case 1:
                    AnimalName = "熊猫";
                    break;
                case 2:
                    AnimalName = "猴子";
                    break;
                case 3:
                    AnimalName = "兔子";
                    break;
                default:
                    break;
            }
            return AnimalName;
        }

        public string GetAnimalColorByID(int ID)
        {
            string AnimalColor = "未知颜色";
            switch (ID)
            {
                case 0:
                    AnimalColor = "红";
                    break;
                case 1:
                    AnimalColor = "绿";
                    break;
                case 2:
                    AnimalColor = "黄";
                    break;
                default:
                    break;
            }
            return AnimalColor;
        }

        public string GetAnimalPrizeByID(int ID)
        {
            string AnimalPrize = "未知开奖模式";
            switch (ID)
            {
                case 0:
                    AnimalPrize = "单颜色单动物";
                    break;
                case 1:
                    AnimalPrize = "单颜色";
                    break;
                case 2:
                    AnimalPrize = "单动物";
                    break;
                case 3:
                    AnimalPrize = "彩金";
                    break;
                case 4:
                    AnimalPrize = "重复开奖";
                    break;
                case 5:
                    AnimalPrize = "闪电（N倍率）";
                    break;
                default:
                    break;
            }
            return AnimalPrize;
        }

        public string GetEnjoyGameNameByID(object gameid)
        {
            int ID = (int)gameid;
            string EnjoyGameName = "未知开奖模式";
            switch (ID)
            {
                case 0:
                    EnjoyGameName = "[庄]";
                    break;
                case 1:
                    EnjoyGameName = "[闲]";
                    break;
                case 2:
                    EnjoyGameName = "[和]";
                    break;
                default:
                    break;
            }
            return EnjoyGameName;
        }

        public string Pre
        {
            get
            {
                if (!string.IsNullOrEmpty(pre))
                    return pre;
                else
                    pre = Server.UrlDecode(Request["pre"]);
                return pre;
            }
        }
        public void CancelSave(object sender, EventArgs arg)
        {
            if (!string.IsNullOrEmpty(Pre))
            {
                Response.Redirect(Pre);
            }
        }
    }
}